package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description: 单例模式之懒汉模式
 */
class Singleton2_1 {
    private static volatile Singleton2_1 instance;

    private Singleton2_1() {}

    public static Singleton2_1 getInstance() {
        if(instance == null) {
            synchronized (Singleton2_1.class) {
                if(instance == null) {
                    instance = new Singleton2_1();
                }
            }
        }
        return instance;
    }
}

public class ThreadDemo23_1 {
    public static void main(String[] args) {
        Singleton2_1 singleton2_1 = Singleton2_1.getInstance();
    }
}
